package com.gimi.cloud.jimi.task.timer;

import com.gimi.cloud.jimi.common.utils.DateUtil;
import com.gimi.cloud.jimi.dao.dao.sys.SysMonitorDao;
import com.gimi.cloud.jimi.entity.sys.SysMonitorEntity;
import com.gimi.cloud.jimi.task.service.SocialSecurityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 社保支持城市的定时器
 *
 * @auther loongs
 * @date 2018/1/11  11:36
 */
@Service
public class QuartzSocialSecurityInfo {

    private SocialSecurityService socialSecurityService;
    private SysMonitorDao sysMonitorDao;

    @Autowired
    public QuartzSocialSecurityInfo(SocialSecurityService socialSecurityService, SysMonitorDao sysMonitorDao) {
        this.socialSecurityService = socialSecurityService;
        this.sysMonitorDao = sysMonitorDao;
    }

    //@Scheduled(cron="*/10 * * * * ?")//每十秒执行一次,测试用
    //@Scheduled(cron="0 0 1 L * ?")//每月的最后一天1:00执行
    public void getProvidentFundInfo() {
        //添加定时器记录
        SysMonitorEntity sysMonitorEntity= new SysMonitorEntity();
        sysMonitorEntity.setStartTime(DateUtil.getNow());
        sysMonitorEntity.setName(Thread.currentThread() .getStackTrace()[1].getClassName() + "." +  Thread.currentThread() .getStackTrace()[1].getMethodName());
        sysMonitorEntity.setCronName("0 0 1 L * ?");
        sysMonitorEntity.setType(1);
        sysMonitorEntity.setRemark("获取社保支持城市的列表定时器");
        //执行操作
        socialSecurityService.getRegionList();
        sysMonitorEntity.setEndTime(DateUtil.getNow());
        sysMonitorDao.insertSelective(sysMonitorEntity);

    }
}
